<?php
/**
 * @author GhostWei
 * @date 2012-7-16
 */
class controller_www_search extends front_controller_panel {	
	
	public function action_index() {
		$this->view->keyword = $keyword = trim($this->_get('keyword'));
		$adapter = new system_paginator_adapter_concept(new picture_special_concept($this->lang));
		$adapter->setCurrentPageNumber(intval($this->_param('page', 1)));
		$adapter->where("special.is_active = 1");
		if($keyword) {
			$K = addslashes($keyword);
			$sql = "SELECT `id` FROM `resource_keyword` WHERE `lang` = '{$this->lang}' AND `name` = '$K'";
			$sql = "SELECT `special_id` FROM `picture_special_keyword` WHERE `keyword_id` IN($sql)";
			$adapter->where("locale.title LIKE ? OR special.id IN($sql)", "%$keyword%");
		}
		$adapter->setLimit(48);
		$adapter->order(array("special.display_order DESC", "special.id DESC"));
		$this->view->headDescription = $this->view->setting('description');
		$this->view->specialList = new system_paginator($adapter);
		$this->_crumbs()->addPage(system_nav_page::create($this->language('搜索') . ':' . $keyword)->setRoute('search/index'));
		$this->render();
	}
	
	public function action_keyword() {
		$name = trim($this->_param('name'));
		$this->view->keyword = $keyword = $this->cache()->keyword()->getInformation(array('id' => $name, 'name' => $name));
		if(!$keyword) {
			throw new front_exception($this->language('该标签不存在'), 404);
		}
		$this->view->headDescription = $name;
		$this->_crumbs()->addPage(system_nav_page::create($keyword['name'])->setRoute('search/keyword')->setParams(array('name' => $name)));
		$this->render();
	}
	
}
